{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "一元运算：指的是对单个元素的操作，如求绝对值、取负、取正、开方、平方根等。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1. ,  1.5,  2. ,  2.5,  3. ],\n",
       "       [ 3.5,  4. ,  4.5,  5. ,  5.5],\n",
       "       [ 6. ,  6.5,  7. ,  7.5,  8. ],\n",
       "       [ 8.5,  9. ,  9.5, 10. , 10.5]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x=np.arange(1,11,step=0.5).reshape(4,5)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\Administrator.DESKTOP-GB232RK\\AppData\\Local\\Temp\\ipykernel_16948\\3539534133.py:7: RuntimeWarning: invalid value encountered in arcsin\n",
      "  np.arcsin(x) # 计算矩阵x的反正弦\n",
      "C:\\Users\\Administrator.DESKTOP-GB232RK\\AppData\\Local\\Temp\\ipykernel_16948\\3539534133.py:8: RuntimeWarning: invalid value encountered in arccos\n",
      "  np.arccos(x) # 计算矩阵x的反余弦\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[0.78539816, 0.98279372, 1.10714872, 1.19028995, 1.24904577],\n",
       "       [1.29249667, 1.32581766, 1.35212738, 1.37340077, 1.39094283],\n",
       "       [1.40564765, 1.418147  , 1.42889927, 1.43824479, 1.44644133],\n",
       "       [1.45368758, 1.46013911, 1.46591939, 1.47112767, 1.47584462]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sqrt(x) # 计算矩阵x的平方根\n",
    "np.exp(x) # 计算矩阵x的指数\n",
    "np.log(x) # 计算矩阵x的对数\n",
    "np.sin(x) # 计算矩阵x的正弦\n",
    "np.cos(x) # 计算矩阵x的余弦\n",
    "np.tan(x) # 计算矩阵x的正切\n",
    "np.arcsin(x) # 计算矩阵x的反正弦\n",
    "np.arccos(x) # 计算矩阵x的反余弦\n",
    "np.arctan(x) # 计算矩阵x的反正切\n",
    "np.abs(x) # 计算矩阵x的绝对值\n",
    "np.sum(x) # 计算矩阵x的元素和\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "二元运算: 加减乘除\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 2. ,  2.5,  3. ,  3.5,  4. ],\n",
       "       [ 4.5,  5. ,  5.5,  6. ,  6.5],\n",
       "       [ 7. ,  7.5,  8. ,  8.5,  9. ],\n",
       "       [ 9.5, 10. , 10.5, 11. , 11.5]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x+1 \n",
    "x-1 \n",
    "x*2 \n",
    "x/2 \n",
    "x**2 \n",
    "x%2 \n",
    "x//2 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "矩阵运算:前提是矩阵的维度要想等\n",
    "两个矩阵(narray)的加减乘除运算 实际上就是对应元素的运算  \n",
    "dot()函数可以计算两个矩阵的乘积    是2个矩阵交叉相乘相加组合成新的矩阵  有点类似于3D数学的 点乘\n",
    "矩阵的转置 transpose()函数可以实现矩阵的转置  \n",
    "矩阵的逆 inverse()函数可以实现矩阵的逆  \n",
    "矩阵的秩 rank()函数可以计算矩阵的秩  \n",
    "矩阵的行列式 det()函数可以计算矩阵的行列式  \n",
    "矩阵的特征值 eig()函数可以计算矩阵的特征值和特征向量  \n",
    "矩阵的QR分解 qr()函数可以实现矩阵的QR分解  \n",
    "矩阵的SVD分解 svd()函数可以实现矩阵的SVD分解  \n",
    "矩阵的条件数 cond()函数可以计算矩阵的条件数  \n",
    "矩阵的迹 trace()函数可以计算矩阵的迹  \n",
    "矩阵的范数 norm()函数可以计算矩阵的范数  \n",
    "矩阵的特征向量与值 eig()函数可以计算矩阵的特征向量与值  \n",
    "矩阵的特征值与向量 eigvals()函数可以计算矩阵的特征值与向量  \n",
    "矩阵的行列式与逆 det()函数可以计算矩阵的行列式与逆  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#两个矩阵(narray)的加减乘除运算 实际上就是对应元素的运算  \n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "machineLearn",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
